<?php
//error_reporting(E_ALL ^ E_NOTICE);
include ("../inc/db_connect.php");
include ("../inc/functions.php");
include ('excel_reader2.php');
$data = new Spreadsheet_Excel_Reader("poistovne.xls",false,'utf-8');
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style>
            table.excel {
                border-style:ridge;
                border-width:1;
                border-collapse:collapse;
                font-family:sans-serif;
                font-size:12px;
            }
            table.excel thead th, table.excel tbody th {
                background:#CCCCCC;
                border-style:ridge;
                border-width:1;
                text-align: center;
                vertical-align:bottom;
            }
            table.excel tbody th {
                text-align:center;
                width:20px;
            }
            table.excel tbody td {
                vertical-align:bottom;
            }
            table.excel tbody td {
                padding: 0 3px;
                border: 1px solid #EEEEEE;
            }
        </style>
    </head>

    <body>
        <?php

        $r = $data->rowcount($sheet_index=0);
        $c = $data->colcount($sheet_index=0);

        for ($i=2;$i<$r+1;$i++) {
            for ($j=1;$j<$c+1;$j++) {
                echo '<b style="color: red">'.$j."</b>:";
                echo $data->val($i,$j);
                echo '|';
            }
            //if (($data->val($i,1)==641) || ($data->val($i,1)==725)) {
            /// osobne cislo
            $user_s = "UPDATE z SET
                       osobne_cislo='".$data->val($i,3)."'
                       WHERE id='".$data->val($i,1)."'";
            $user_q = MySQL_Query ($user_s);
            // poistovna
            if ($data->val($i,6)!=-1) {
                $x_s = "SELECT * FROM z_zdravotna_poistovna WHERE zid='".$data->val($i,1)."' ";
                $x_q = MySQL_Query ($x_s);
                $x = MySQL_Fetch_Array($x_q);
                if (isset($x['id'])) {
                    echo $y_s = "UPDATE z_zdravotna_poistovna SET pid='".$data->val($i,6)."', datum_pridania='".date('Y-n-d')."' WHERE id='".$x['id']."'";
                    $y_q = MySQL_Query ($y_s);
                    echo '<p style="color:red">poistovna'."MySQL error ".mysql_errno().": ".mysql_error()."\n<br>".$z_uloz_i.'</p>';
                } else {
                    echo $y_s = "INSERT INTO z_zdravotna_poistovna (id,pid,datum_pridania,zid) VALUES (NULL,'".$data->val($i,6)."','".date('Y-n-d')."',".$data->val($i,1).")";
                    echo '<p style="color:red">poistovna'."MySQL error ".mysql_errno().": ".mysql_error()."\n<br>".$z_uloz_i.'</p>';
                    $y_q = MySQL_Query ($y_s);
                }
            }
            //}
            echo '<br/>';
        }

        echo $data->dump(true,true);
        ?>
        <?php
//echo $data->val(10,A);
        ?>
    </body>
</html>
